function onBridgeReady() {
	if (WeixinJSBridge) {
		WeixinJSBridge.call('hideOptionMenu');
	}
}

if (typeof WeixinJSBridge == "undefined") {
	if (document.addEventListener) {
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	} else if (document.attachEvent) {
		document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
		document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
} else {
	onBridgeReady();
}

var Manager = {
	config : {},
	file : [],
	order_type : 0,
	init : function(config) {
		var _this = this;
		$.extend(_this.config, config);
		_this.init_grid();
		_this.init_btn();
	},

	init_btn : function() {
		var _this = this;
		$("#page_info button").on("click", function() {
			var query_param = $('#data_table').TableGrid('getparam');
			switch ($(this).data("type")) {
			case "up":
				query_param.page -= 1;
				break;
			case "down":
				query_param.page += 1;
				break;
			}
			$('#data_table').TableGrid('param', query_param);
			$('#data_table').TableGrid('reload');
		});
		$("#order_type").dropdown_list({
			change : function($this, param) {
				_this.order_type = $($this).data("value");
			}
		});
		$("#search_btn").on("click", function(e) {
			e.preventDefault();
			var query_param = $('#data_table').TableGrid('getparam');
			query_param.status = _this.order_type;
			query_param.keyword = $("#keyword").val();
			$('#data_table').TableGrid('param', query_param);
			$('#data_table').TableGrid('reload');
		});
		$("#data_table").on(
				"click",
				".edit_btn",
				function(e) {
					e.preventDefault();
					var id = $(this).data("id");
					var url = _this.config.review + id + '/'
							+ _this.config.merid + '/' + _this.config.openid;
					$.get(url, function(_dat) {
						if (_dat.status) {
							$('#data_table').TableGrid('reload');
						} else {
							tips(_dat.info);
						}
					});
				});
	},
	init_grid : function() {
		var _this = this;
		$('#data_table').TableGrid({
			url : _this.config.read_url,
			select_all : false,
			load_after_init : true,
			pagination : false,
			param : {
				mer_id : _this.config.mer_id,
			},
			row_style : function(row, index) {
				if (row.status == 1) {
					return 'info';
				}
			},
			after_load : function(page, page_size, total) {
				if (page == 1) {
					$("#page_info button").eq(0).prop("disabled", true);
				} else {
					$("#page_info button").eq(0).prop("disabled", false);
				}
				var total_page = Math.ceil(total / page_size);
				if (page == total_page) {
					$("#page_info button").eq(2).prop("disabled", true);
				} else {
					$("#page_info button").eq(2).prop("disabled", false);
				}
				$("#page_info button").eq(1).html(page + "/" + total_page);
			}
		});
	}
};
var opt_edit = function(value, row, index) {
	if (row.status == 0) {
		return '<a class="btn btn-warning edit_btn" data-id="'
				+ row.id
				+ '" href="#" taget="_blank" title="审核"><i class="fa fa-pencil-square-o "></i>审核</a>';
	} else {
		return "已审核";
	}
}
var opt_details = function(value, row, index) {
	return '<a href="' + Manager.config.details + row.id + '/'
			+ Manager.config.merid + '/' + Manager.config.openid
			+ '" taget="_blank">' + row.address + '</a>';
}
function format_status() {

}